library(ClusterR)
## Loading required package: gtools
library(knitr)
library(rgl)
library(rglwidget)
## The functions in the rglwidget package have been moved to rgl.
knit_hooks$set(webgl = hook_webgl)
library(scatterplot3d)
library(ggplot2)
library(sm)
## Package 'sm', version 2.2-5.4: type help(sm) for summary information
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
clustME <- function(numberOfClusters,clust,loc_gc) {
  cols <- paste0("clust",c(1:numberOfClusters))
  clusStats = data.frame(K=numeric(),WithinSS=numeric())
  i=1
  for(i in 1:numberOfClusters){
    print(i)
    km_rc = KMeans_rcpp(clust, clusters = i, num_init = 100, max_iters = 1000, 
                      
                      initializer = 'optimal_init', threads = 4, verbose = T)
    
    tmp=data.frame(km_rc$clusters)
    colnames(tmp)=c(cols[i])
    loc_gc=cbind(loc_gc,tmp)
    print(colnames(loc_gc))
    tmp2 = data.frame(K=c(i),WithinSS=c(mean(km_rc$between.SS_DIV_total.SS)))
    clusStats= rbind(clusStats,tmp2)
  }
  save(clusStats,file = "clusStats.RData")

  return(loc_gc)
}

## 
## Attaching package: 'MASS'
## The following object is masked from 'package:dplyr':
## 
##     select
## The following object is masked from 'package:sm':
## 
##     muscle